use actix_web::web::Json;
use actix_web::HttpResponse;
use actix_web::{get, post};

use crate::service::role_service::RoleService;
use fast_common::common::api_result::Api;
use fast_common::models::role::{Role, RoleVo};

///
/// ```添加角色```
///
#[post("new_role")]
pub async fn new_role(arg: Json<Role>) -> HttpResponse {
    let result = RoleService::new_role(arg.into_inner()).await;
    return Api::from_any_result(result).await.to_response_of_json().await;
}

///
/// ```修改角色```
///
#[post("update_role")]
pub async fn update_role(arg: Json<Role>) -> HttpResponse {
    let result = RoleService::update_role(arg.into_inner()).await;
    return Api::from_any_result(result).await.to_response_of_json().await;
}

#[get("delete_role")]
pub async fn delete_role(arg: Json<Role>) -> HttpResponse {
    let result = RoleService::delete_role(arg.into_inner()).await;
    return Api::from_any_result(result).await.to_response_of_json().await;
}

#[get("role_list")]
pub async fn role_list(arg: Json<RoleVo>) -> HttpResponse {
    let result =RoleService::role_list(arg.into_inner()).await;
    return Api::from_any_result(result).await.to_response_of_json().await;

}
